package cn.tedu.test;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * 1.java.net.ConnectionException:Connection refuse:connect
 * 解释:客户端Socket连接服务器，服务器未响应，会抛如上异常。
 * 请写一段代码重现该异常；
 * 2.java.net.SocketException:Connection reset
 * 解释：服务器端按照行读，客户端未按照行刷新写。
 * 请写一段代码重现该异常；
 */
public class Work_20 {
    public static void main(String[] args) throws IOException {
        ServerSocket server=new ServerSocket(8888);
        System.out.println("开启！");
        Socket s = server.accept();
        System.out.println("已连接");
        BufferedReader br=new BufferedReader(
                new InputStreamReader(s.getInputStream()));
        String str="";
        while ((str=br.readLine())!=null) {

            System.out.println(str);

        }
    }
}
class User{
    public static void main(String[] args) throws IOException {
        Socket s=new Socket("127.0.0.1",8888);
        System.out.println("连接成功");
        PrintWriter pw=new PrintWriter(s.getOutputStream());
        pw.write("apple");
        pw.write("apple");
        pw.write("apple");
        pw.close();


    }


}
